package com.sgb.kjwl.view.ui.adapter.transport;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.swgk.core.base.model.entity.VideoBean;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;


public class GoodsInfoVideoAdapter extends BaseRecycleAdapter<VideoBean> {

    public GoodsInfoVideoAdapter(Context context, List<VideoBean> datas) {
        super(context, R.layout.item_goods_video, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, VideoBean videoBean) {
        if (videoBean.isCheckMoreVideos()) {
            ((ImageView) holder.getView(R.id.tag_cuxiao)).setImageDrawable(context.getResources().getDrawable(R.drawable.check_more_video));
            ((ImageView) holder.getView(R.id.logo_view)).setImageDrawable(context.getResources().getDrawable(R.drawable.gray_radius_bkg));
            (holder.getView(R.id.more_video_text)).setVisibility(View.VISIBLE);
            (holder.getView(R.id.title_view)).setVisibility(View.GONE);
        } else {
            ((ImageView) holder.getView(R.id.tag_cuxiao)).setImageDrawable(context.getResources().getDrawable(R.mipmap.icn_play));
            (holder.getView(R.id.more_video_text)).setVisibility(View.GONE);
            (holder.getView(R.id.title_view)).setVisibility(View.VISIBLE);
            holder.setBinding(BR.viewModel, videoBean);
            setItemUISize(holder);
            RequestOptions options = new RequestOptions().placeholder(context.getResources().getDrawable(R.drawable.video_null_icon));
            Glide.with(context).load(videoBean.getCover()).apply(options).into((ImageView) holder.getView(R.id.logo_view));
        }
    }


    private void setItemUISize(ItemViewHolder holder) {
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams)
                holder.getView(R.id.content_view).getLayoutParams();
        //2.1.8.8 董事长手机屏幕显示 宽高调窄
        params.height = context.getResources().getDimensionPixelOffset(R.dimen.dp260);
        if (datas.size() == 1) {
            params.width = ViewGroup.LayoutParams.MATCH_PARENT;
        } else {
            params.width = context.getResources().getDimensionPixelOffset(R.dimen.dp194);
            params.rightMargin = 0;
        }
        holder.getView(R.id.content_view).setLayoutParams(params);
    }
}
